﻿package forms
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Point;
	
	public class Spiral extends Bitmap
	{
		public function Spiral ($width:Number = 100, $height:Number = 100, $color:uint = 0x000000)
		{
			var shape:BitmapData     = new BitmapData ($width, $height, true, 0x00ffffff);
			var centerPoint:Point    = new Point ($width / 2, $height / 2);
			var totalDistance:Number = Point.distance ( new Point (), centerPoint);
			var currentPoint:Point;
			var distance:Number;
			var randomAlpha:uint;
			var pixelColor:uint;
			
			for (var row:int = 0; row < shape.height; row++)
			{
				for (var col:int = 0; col < shape.width; col++)
				{
					currentPoint    = new Point (col, row);
					distance        = Point.distance (currentPoint, centerPoint) / totalDistance;
					randomAlpha     = Math.round ( (1 / distance) * 255 );
					pixelColor      = (randomAlpha << 24) + $color;
					shape.lock ();
					shape.setPixel32(col, row, pixelColor);
					shape.unlock ();
				}
			}
			
			super (shape);
		}
		
	}
}